package com.study.flink.java.day03_windows;

import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import org.apache.flink.util.Collector;

public class MyProcessWindowFunction extends ProcessWindowFunction<Tuple3<String, Long, Long>, String, Long, TimeWindow> {
    @Override
    public void process(Long aLong, Context context, Iterable<Tuple3<String, Long, Long>> elements, Collector<String> out) throws Exception {
        // 统计每个窗口内的所有数据的 f0字段加起来共有多少个单词
        // 也就做单个窗口的 wordcount
        Long count = 0L;
        for (Tuple3<String, Long, Long> element : elements) {
            count += element.f0.split(" ").length;
        }
        out.collect("window: " + context.window() + " word count: " + count);
    }
}
